<script>
import {login} from "@/api/user";

export default {
  name: "home",
  data() {
    return {
      formLabelWidth: '80px',
      form: {
        username: '',
        password: '',
      }
    }
  },
  methods: {
    onSubmit() {
      // 发送http请求  认证
      login(this.form).then(response => {
        if (response.code == 200) {
          this.$message.success(response.message)
          // 跳转路由  /home
          this.$router.push('/home')
        } else {
          this.$message.error(response.message)
        }
      })
    }
  }
}
</script>

<template>
  <div id="container">
    <h2>登录</h2>
    <el-form :model="form">
      <el-form-item label="用户名" :label-width="formLabelWidth">
        <el-input v-model="form.username" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="密码" :label-width="formLabelWidth">
        <el-input type="password" v-model="form.password" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即登录</el-button>
      </el-form-item>
    </el-form>
    <router-link to="/register">没有账号?,立即注册</router-link>
  </div>

</template>

<style scoped>
#container {
  width: 450px;
  height: 350px;
  box-shadow: 0 0 15px #ccc;
  margin: 100px auto;
  color: #42b983;
  padding: 20px;
  border-radius: 15px;
}

h2 {
  margin-bottom: 70px;
}
</style>